package com.ncloud.aaaa.service.impl;

import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ncloud.aaaa.model.Func;
import com.ncloud.aaaa.repository.FuncRepository;
import com.ncloud.aaaa.service.FuncService;
import com.ncloud.common.exception.UserException;

@Service
public class FuncServiceImpl implements FuncService {
	
	private static final Logger logger = LogManager.getLogger(FuncServiceImpl.class);
	@Autowired
	private FuncRepository repository;
	
	@Override
	public JSONArray getFuncList(JSONObject json) {
		if(!json.containsKey("userID")){
			throw new UserException("2001", "传入参数有误");
		}
		String userId = json.getString("userID");
		List<Func> funcList = repository.getFuncListByUserId(Long.parseLong(userId));
		return JSON.parseArray(JSON.toJSONString(funcList));
	}

	@Override
	public Boolean hasFuncCode(JSONObject json) {
		if(!json.containsKey("userID") || !json.containsKey("funcCode")){
			throw new UserException("2001", "传入参数有误");
		}
		Boolean result = false;
		String userId = json.getString("userID");
		String funcCode = json.getString("funcCode");
		List<Func> funcList = repository.getFuncListByUserIdAndFuncCode(Long.parseLong(userId),funcCode);
		if(funcList!=null && funcList.size()>0) result = true;
		return result;
	}


}
